package com.xxx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxx.pojo.User;
import com.xxx.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/8/30 10:01
 * @Copyright 博为峰
 */
@Controller
@RequestMapping("/user")
//@Log4j2
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/selectByPrimaryKey")
    public String selectByPrimaryKey(Model model) {
        final User user = userService.selectByPrimaryKey("270272022ab44f19830fd9aaccbea1f5");
        System.out.println("user = " + user);
        model.addAttribute("user", user);
        return "user";
    }

    @RequestMapping("/selectUserList")
    public String selectUserList(int pageNum, ModelMap map) {
        PageHelper.startPage(pageNum, 10);
        final List<User> userList = userService.selectUserList();
        final PageInfo<User> pageInfo = new PageInfo<>(userList);
        map.put("pageInfo", pageInfo);
        return "user_list";
    }

    @RequestMapping("/index1")
    public String index1() {
        return "index1";
    }

    @RequestMapping("/index")
    public String index() {
        return "index";
    }
}
